package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.Result;
import com.sky.service.DishService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/admin/dish")
@Api(tags = "菜品管理相关接口")
public class DishController {
    @Autowired
    private DishService dishService;

    @PostMapping
    @ApiOperation("新增菜品")
    public Result addDish(@RequestBody DishDTO dto){
        return dishService.addDish(dto);
    }

    @GetMapping("/page")
    @ApiOperation("菜品分页查询")
    public Result queryDishesByPage(DishPageQueryDTO dto){
        return dishService.queryDishesByPage(dto);
    }

    @DeleteMapping
    @ApiOperation("删除菜品")
    public Result deleteDishesByIds(@RequestParam("ids") List<Long> ids){
        return dishService.deleteDishesByIds(ids);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询菜品")
    public Result queryDishById(@PathVariable("id") Long id){
        return dishService.queryDishById(id);
    }

    @PutMapping
    @ApiOperation("修改菜品")
    public Result updateDishById(@RequestBody DishDTO dto){
        return dishService.updateDishById(dto);
    }

    @GetMapping("/list")
    @ApiOperation("根据分类id查询菜品列表")
    public Result queryDishesByCategoryId(Long categoryId){
        return dishService.queryDishesByCategoryId(categoryId);
    }
}
